<div class="layui-fluid layui-anim febs-anim" id="businesses-teachProgram" lay-title="教学计划">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="user-table-form">
                        <fieldset class="layui-elem-field layui-field-title">
                            <legend style="font-size: 15px;font-weight: bolder;">批量查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <div class="layui-col-md12">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">批次</label>
                                        <div class="layui-input-inline">
                                            <select name="batchId" id="batchId_TeachProgram" lay-filter="cboBatch_TeachProgram">


                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">院校</label>
                                        <div class="layui-input-inline">
                                            <select name="collegeId" id="cboCollege_TeachProgram" lay-filter="cboCollege_TeachProgram">


                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">层次</label>
                                        <div class="layui-input-inline">
                                            <select name="levelId" id="levelId_TeachProgram" lay-filter="cboLevel_TeachProgram" >
                                                <option value="">请选择</option>
                                                <option value="1">专升本</option>
                                                <option value="2">高起本</option>
                                                <option value="3">高起专</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">类别</label>
                                        <div class="layui-input-inline">
                                            <select name="subtypeId" id="cboType_TeachProgram" lay-filter="cboType_TeachProgram">

                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">专业</label>
                                        <div class="layui-input-inline">
                                            <select name="majorId" id="cboMajor_TeachProgram" lay-filter="cboMajor_TeachProgram">

                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">方式</label>
                                        <div class="layui-input-inline">
                                            <select name="modeId" id="modeId">
                                                <option value="">全部</option>
                                                <option value="4">函授</option>
                                                <option value="5">业余</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">学年</label>
                                        <div class="layui-input-inline">
                                            <select name="absoYearId" id="cboYear_TeachProgram" lay-filter="cboYear_TeachProgram">


                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">学期</label>
                                        <div class="layui-input-inline">
                                            <select name="absoSemId" id="cboTerm_TeachProgram" lay-filter="cboTerm_TeachProgram">
                                                <option value="">全部</option>

                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>



                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">

                                    </div>
                                    <div class="layui-inline">

                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="query">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                            </div>
                        </div>




                        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">

                            <div class="layui-row">


                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="add">
                                    <i class="layui-icon layui-icon-plus-circle">批次复制</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="addNew">
                                    <i class="layui-icon layui-icon-plus-circle">新增批次</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action">
                                    <i class="layui-icon layui-icon-export" id="export">导出数据</i>
                                </div>
                            </div>

                        </blockquote>
                    </form>
                    <table lay-filter="teachProgramTable" lay-data="{id: 'teachProgramTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="teachProgram-option">

    <a lay-event="edit"><i class="layui-icon febs-edit-area febs-blue" title="修改计划">&#xe7a4;</i></a>
    <a lay-event="del"><i class="layui-icon layui-icon-poweroff febs-edit-area febs-red " title="停用计划"></i></a>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'form', 'table', 'febs','xmSelect','element'], function () {
        let $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            $view = $('#businesses-teachProgram'),
            $query = $view.find('#query'),
            $add = $view.find('#add'),
            $addNew = $view.find('#addNew'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            $export=$view.find('#export'),
            sortObject = {field: 'batchName', type: null},
            tableIns,
            createTimeFrom,
            createTimeTo,
            deptXmlSelect;

        form.render();
        var mycols =[];
        initTable();



        table.on('tool(teachProgramTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'del') {
                febs.modal.confirm('停用批次', '确定停用该批次？', function () {
                    deleteTeachProgram(data.id);
                    console.log(data)
                });
            }
            if (layEvent === 'edit') {
                febs.modal.open('修改教学计划信息', 'teachProgram/update/' + data.id, {

                    area: $(window).width() <= 750 ? '90%' : '40%',
                    btn: ['提交', '取消'],
                    yes: function (index, layero) {
                        // 单击之后提交按钮不可选,防止重复提交

                        var a=$('#teachProgram-update').find('#cboSchool_TeachProgram').val();
                        var b=$('#teachProgram-update').find('#cboYear_TeachProgram_add').val();
                        var c=$('#teachProgram-update').find('#cboTerm_TeachProgram_add').val();
                        if(a!=''&&b!=''&&c!=''){
                             $('#teachProgram-update').find('#submit').trigger('click');
                        }else {
                            febs.alert.warn('信息不能为空！');
                        }
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
        });
        document.onkeydown = function (e) { // 回车提交表单
// 兼容FF和IE和Opera
            var theEvent = window.event || e;
            var code = theEvent.keyCode || theEvent.which || theEvent.charCode;

            if (code == 13) {
                $query.click();
            }
        }
        table.on('sort(teachProgramTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $export.on('click',function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
            params.pageNum = $view.find(".layui-laypage-em").next().html();
            febs.download(ctx + 'teachProgram/excel', params, '教学计划表.xlsx');
        });

        $add.on('click', function () {
                febs.modal.open('批次复制', 'teachProgram/add', {
                btn: ['提交', '重置'],
                area:['250px', '350px'],
                yes: function (index, layero) {
                    $('#teachProgram-add').find('#submit').trigger('click');
                },
                btn2: function () {
                    $('#teachProgram-add').find('#reset').trigger('click');
                    return false;
                }
            });
        });

        $addNew.on('click', function () {
            var k = 0;
            febs.modal.open('新增批次', 'teachProgram/addNew', {
                area: $(window).width() <= 450 ? '40%' : '30%',
                btn: ['提交', '取消'],
                yes: function (index, layero) {

                    var d = $('#teachProgram-addNew').find('#college_TeachProgram_addNew').val();
                    var h = $('#teachProgram-addNew').find('#cboBatch_TeachProgram_addNew').val();
                    var e = $('#teachProgram-addNew').find('#cboMajor_TeachProgram_addNew').val();
                    var i = $('#teachProgram-addNew').find('#cboMode_TeachProgram_addNew').val();
                    var f = $('#teachProgram-addNew').find('#cboType_TeachProgram_addNew').val();
                    var g = $('#teachProgram-addNew').find('#cboLevel_TeachProgram_addNew').val();
                    var a = $('#teachProgram-addNew').find('#cboSchool_TeachProgram_addNew').val();
                    var b = $('#teachProgram-addNew').find('#cboYear_TeachProgram_addNew').val();
                    var c = $('#teachProgram-addNew').find('#cboTerm_TeachProgram_addNew').val();
//                    console.log( d);
//                    console.log(e);
//                    console.log(f);
//                    console.log(g);
//                    console.log(h);
//                    console.log(i);


                    k++;
                    console.log(k)
                    if (k == 1) {
                        if (a != '' && b != '' && c != '' && d != '' && e != '' && f != '' && g != '' && h != '' && i != '') {
                            $('#teachProgram-addNew').find('#submit').trigger('click');

                        } else {
                            febs.alert.warn('信息不能为空！');
                        }
                    } else {
                        febs.alert.warn("不能重复提交！")
                    }

                },
                btn2: function () {
                    layer.closeAll();
                }
            })
        });


        //批次下拉框遍历
        $(function () {
            $.get("teachProgram/batchList", function (obj) {

                // selectIDc=obj.data;
                var str="<option value=''>全部</option>";
                layui.each (obj.data, function (index, item) {
                    str=str+"<option value='" + this.id + "'>" + this.batchName + "</option>";

                });

                $ ("#batchId_TeachProgram"). html(str);
                layui.use('form', function () {
                    var form = layui.form;
                    form.render();
                });
            });
        });

        //院校下拉框遍历
        $(function () {
            $.get("homework/collegeList", function (obj) {
                console.log(obj.data);
//                console.log(obj.data.rows.name)
                var str1="<option value=''>全部</option>";
                layui.each(obj.data, function (index, item) {
                    str1 = str1 +"<option value='" + this.id + "'>" + this.name + "</option>";

                });
                $("#cboCollege_TeachProgram").html(str1);
                layui.use('form', function () {
                    var form = layui.form;
                    form.render();
                });
            });
        });
        //类别下拉框
        initSubject();
        function initSubject() {
            $.ajax({
                type: 'get',
                url: 'teachProgram/subjectCategoryList',
                success: function (res) {
                    console.log(res.data[0]);
                    $("#cboType_TeachProgram").append("<option value=''>全部</option>")
                    layui.each(res.data, function (index, item) {
                        $("#cboType_TeachProgram").append("<option value='" + this.id + "'>" + this.fullName + "</option>");
                    });
                    //渲染select
                    form.render('select');

                }
            })
        }


        form.on("select(cboCollege)", function (obj) {
            var collegeId = obj.value;
            console.log(obj);
            initLevel(collegeId);
        });

        initMajor();
        //专业下拉框
        function initMajor() {
            $.ajax({
                type: 'get',
                url: 'teachProgram/majorList',
                success: function (res) {
                    console.log(res.data[0]);
                    $("#cboMajor_TeachProgram").append("<option value=''>全部</option>")
                    layui.each(res.data, function (index, item) {
                        $("#cboMajor_TeachProgram").append("<option value='" + this.id + "'>" + this.fullName + "</option>");
                    });
                    //渲染select
                    form.render('select');

                }
            })
        }

        initYear();
        function initYear() {
            $.ajax({
                type: 'get',
                url: 'teachProgram/yearList',
                success: function (res) {
                    console.log(res.data)

                    $("#cboYear_TeachProgram").append("<option value=''>全部</option>")
                    layui.each(res.data, function (index, item) {
                        $("#cboYear_TeachProgram").append("<option value='" + this.id + "'>" + this.yearName + "</option>");
                    });
                    //渲染select
                    form.render('select');

                }
            })
        }

        form.on("select(cboYear_TeachProgram)", function (obj) {
            var absoYearId = obj.value;
            console.log(obj);
            initTerm(absoYearId);
        });

        //学期下拉框
        function initTerm(id) {
            $.ajax({
                type: 'get',
                url: 'teachProgram/termList',
                data: {absoYearId: id},
                success: function (res) {
                    console.log(res);
                    $("#cboTerm_TeachProgram").empty();
                    $("#cboTerm_TeachProgram").append("<option value=''>全部</option>")
                    layui.each(res.data, function (index, item) {
                        $("#cboTerm_TeachProgram").append("<option value='" + this.id + "'>" + this.semesterName + "</option>");
                    });
                    //渲染select
                    form.render('select');

                }
            })
        }

        $query.on('click', function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });
        $reset.on('click', function () {
            //下拉框重置
            $("#cboMajor_TeachProgram").empty();
            $("#cboMajor_TeachProgram").append("<option value=''>全部</option>");
            $("#cboLevel_TeachProgram").empty();
            $("#cboLevel_TeachProgram").append("<option value=''>全部</option>");
            $searchForm[0].reset();
            sortObject.type = 'null';
            tableIns.reload({where: getQueryParams(true), page: {curr: 1}, initSort: sortObject});
        });

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'teachProgramTable',
                url: ctx + 'teachProgram/list',
                cols: [[
//                    {type: 'checkbox'},
                    {field: 'batchName', title: '批次', minWidth: 80,sort: true},
                    {field: 'collegeName', title: '院校名称', minWidth: 150 },

                    {field: 'level', title: '层次', minWidth: 80},
                    {field: 'typeName', title: '类别',minWidth: 120},
                    {field: 'majorName', title: '专业',minWidth: 150},

                    {field: 'studyMode', title: '培养方式', minWidth: 80},
                    {field: 'school', title: '学制',minWidth: 80},
                    {field: 'year', title: '学年',minWidth: 80},
                    {field: 'semester', title: '学期',minWidth: 80},
                    {field: 'courseName', title: '课程名称 '},

                    {title: '操作', toolbar: '#teachProgram-option', minWidth: 100}
                ]]
            });
        }

        function getQueryParams(flag) {
            let params = $searchForm.serializeJson();
            return params;
        }

        function deleteTeachProgram(id) {
            console.log(id)
            febs.get(ctx + 'teachProgram/remove/' + id, null, function () {

                febs.alert.success('批次停用成功');
                $query.click();
            });
        }
    })
</script>